<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$manage_op=array('confirm','cancel','agree','disagree');
if(in_array($_RQ['op'],$manage_op)){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择拼团！','error');
	}
}
$return=array();
$return['status']=$this->team_status;
$tabs=array(
	array('op'=>'list','title'=>'全部拼团'),
	array('op'=>'list0','title'=>'拼团中'),
	array('op'=>'list1','title'=>'拼团成功'),
	array('op'=>'list2','title'=>'拼团失败'),
); 
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$data['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['nickname'])){
		$data['nickname like']='%'.trim($_RQ['nickname']).'%';
		$headsid=pdo_getcolumn('core_members',$data,'id');
		$params['headsid']=intval($headsid);
		$return['params']['nickname']=$_RQ['nickname'];
	}
	if($_RQ['id']){
		$params['id']=intval($_RQ['id']);
		$return['params']['id']=$_RQ['id'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','groupid','goodsid','cid','headsid','createtime','status');
	$list=pdo_getslice('jy_aligroup_groups_team',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			//修改状态
			$group=pdo_get('jy_aligroup_groups',array('id'=>$item['groupid'],'uniacid'=>$_SESSION['uniacid']));
			$goods=pdo_get('jy_weishop_goods',array('id'=>$item['goodsid'],'uniacid'=>$_SESSION['uniacid']));
			$corps=pdo_get('jy_aligroup_groups_corps',array('id'=>$item['cid'],'uniacid'=>$_SESSION['uniacid']));
			//该拼团需要人数
			$item['groupnum']=$group['groupnum'];
			//已有人数
			$item['teamnum']=pdo_count('jy_aligroup_groups_order',array('uniacid'=>$_SESSION['uniacid'],'teamid'=>$item['id'],'status'=>1));
			//到期时间
			$item['endtime']=$group['timeout']*60*60+$item['createtime'];
			if($item['status']!=1 && $item['endtime']<time()){
				$item['status']=2;
			}						  
			$item['member']=cfc('core')->member_show($item['headsid']);
			$item['grouptitle']=$group['title'];
			$item['corpstitle']=$corps['title'];
			$item['goodstitle']=$goods['title'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'id','title'=>'团ID','type'=>'string'),
			array('name'=>'member','title'=>'团长信息_Member','type'=>'member'),
			array('name'=>'teamnum','title'=>'已参团人数','type'=>'string'),
			array('name'=>'groupnum','title'=>'成团人数','type'=>'string'),
			array('name'=>'grouptitle','title'=>'活动名称','type'=>'string'),
			array('name'=>'corpstitle','title'=>'战队名','type'=>'string'),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'createtime','title'=>'开团时间','type'=>'time'),
			array('name'=>'endtime','title'=>'到期时间','type'=>'time'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		)),
		'search'=>array(
			array('name'=>'id','title'=>'团ID','type'=>'string','width'=>15),
			array('name'=>'nickname','title'=>'团长昵称','type'=>'string','width'=>15),
		)
	);
	$return['htmls']=$htmls;
	
	exi($return);
}

if($_RQ['op']=='list0'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['status']=0;
	$data['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['nickname'])){
		$data['nickname like']='%'.trim($_RQ['nickname']).'%';
		$headsid=pdo_getcolumn('core_members',$data,'id');
		$params['headsid']=intval($headsid);
		$return['params']['nickname']=$_RQ['nickname'];
	}
	if($_RQ['id']){
		$params['id']=intval($_RQ['id']);
		$return['params']['id']=$_RQ['id'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','groupid','goodsid','cid','headsid','createtime');
	$list=pdo_getslice('jy_aligroup_groups_team',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$heads=pdo_get('jy_weishop_member',array('id'=>$item['headsid'],'uniacid'=>$_SESSION['uniacid']));
			$member=pdo_get('core_members',array('id'=>$item['headsid'],'uniacid'=>$_SESSION['uniacid']));
			$group=pdo_get('jy_aligroup_groups',array('id'=>$item['groupid'],'uniacid'=>$_SESSION['uniacid']));
			$goods=pdo_get('jy_weishop_goods',array('id'=>$item['goodsid'],'uniacid'=>$_SESSION['uniacid']));
			$corps=pdo_get('jy_aligroup_groups_corps',array('id'=>$item['cid'],'uniacid'=>$_SESSION['uniacid']));
			//该拼团需要人数
			$item['groupnum']=$group['groupnum'];
			//已有人数
			$item['teamnum']=pdo_count('jy_aligroup_groups_order',array('uniacid'=>$_SESSION['uniacid'],'teamid'=>$item['id'],'status'=>1));
			//到期时间
			$item['endtime']=$group['endtime']*60*60+$item['createtime'];
						  
			$item['nickname']=$heads['nickname']?$heads['nickname']:$member['nickname'];
			$item['grouptitle']=$group['title'];
			$item['corpstitle']=$corps['title'];
			$item['goodstitle']=$goods['title'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'id','title'=>'团ID','type'=>'string'),
			array('name'=>'nickname','title'=>'团长昵称','type'=>'string'),
			array('name'=>'teamnum','title'=>'已参团人数','type'=>'string'),
			array('name'=>'groupnum','title'=>'成团人数','type'=>'string'),
			array('name'=>'grouptitle','title'=>'活动名称','type'=>'string'),
			array('name'=>'corpstitle','title'=>'战队名','type'=>'string'),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'createtime','title'=>'开团时间','type'=>'string'),
			array('name'=>'endtime','title'=>'到期时间','type'=>'time'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		)),
		'search'=>array(
			array('name'=>'id','title'=>'团ID','type'=>'string','width'=>15),
			array('name'=>'nickname','title'=>'团长昵称','type'=>'string','width'=>15),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='list1'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['status']=1;
	$data['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['nickname'])){
		$data['nickname like']='%'.trim($_RQ['nickname']).'%';
		$headsid=pdo_getcolumn('core_members',$data,'id');
		$params['headsid']=intval($headsid);
		$return['params']['nickname']=$_RQ['nickname'];
	}
	if($_RQ['id']){
		$params['id']=intval($_RQ['id']);
		$return['params']['id']=$_RQ['id'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','groupid','goodsid','cid','headsid','createtime');
	$list=pdo_getslice('jy_aligroup_groups_team',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$heads=pdo_get('jy_weishop_member',array('id'=>$item['headsid'],'uniacid'=>$_SESSION['uniacid']));
			$member=pdo_get('core_members',array('id'=>$item['headsid'],'uniacid'=>$_SESSION['uniacid']));
			$group=pdo_get('jy_aligroup_groups',array('id'=>$item['groupid'],'uniacid'=>$_SESSION['uniacid']));
			$goods=pdo_get('jy_weishop_goods',array('id'=>$item['goodsid'],'uniacid'=>$_SESSION['uniacid']));
			$corps=pdo_get('jy_aligroup_groups_corps',array('id'=>$item['cid'],'uniacid'=>$_SESSION['uniacid']));
			//该拼团需要人数
			$item['groupnum']=$group['groupnum'];
			//已有人数
			$item['teamnum']=pdo_count('jy_aligroup_groups_order',array('uniacid'=>$_SESSION['uniacid'],'teamid'=>$item['id'],'status'=>1));
			//到期时间
			$item['endtime']=$group['endtime']*60*60+$item['createtime'];
						  
			$item['nickname']=$heads['nickname']?$heads['nickname']:$member['nickname'];
			$item['grouptitle']=$group['title'];
			$item['corpstitle']=$corps['title'];
			$item['goodstitle']=$goods['title'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'id','title'=>'团ID','type'=>'string'),
			array('name'=>'nickname','title'=>'团长昵称','type'=>'string'),
			array('name'=>'teamnum','title'=>'已参团人数','type'=>'string'),
			array('name'=>'groupnum','title'=>'成团人数','type'=>'string'),
			array('name'=>'grouptitle','title'=>'活动名称','type'=>'string'),
			array('name'=>'corpstitle','title'=>'战队名','type'=>'string'),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'createtime','title'=>'开团时间','type'=>'string'),
			array('name'=>'endtime','title'=>'到期时间','type'=>'time'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		)),
		'search'=>array(
			array('name'=>'id','title'=>'团ID','type'=>'string','width'=>15),
			array('name'=>'nickname','title'=>'团长昵称','type'=>'string','width'=>15),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='list2'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['status']=2;
	$data['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['nickname'])){
		$data['nickname like']='%'.trim($_RQ['nickname']).'%';
		$headsid=pdo_getcolumn('core_members',$data,'id');
		$params['headsid']=intval($headsid);
		$return['params']['nickname']=$_RQ['nickname'];
	}
	if($_RQ['id']){
		$params['id']=intval($_RQ['id']);
		$return['params']['id']=$_RQ['id'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','groupid','goodsid','cid','headsid','createtime');
	$list=pdo_getslice('jy_aligroup_groups_team',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$heads=pdo_get('jy_weishop_member',array('id'=>$item['headsid'],'uniacid'=>$_SESSION['uniacid']));
			$member=pdo_get('core_members',array('id'=>$item['headsid'],'uniacid'=>$_SESSION['uniacid']));
			$group=pdo_get('jy_aligroup_groups',array('id'=>$item['groupid'],'uniacid'=>$_SESSION['uniacid']));
			$goods=pdo_get('jy_weishop_goods',array('id'=>$item['goodsid'],'uniacid'=>$_SESSION['uniacid']));
			$corps=pdo_get('jy_aligroup_groups_corps',array('id'=>$item['cid'],'uniacid'=>$_SESSION['uniacid']));
			//该拼团需要人数
			$item['groupnum']=$group['groupnum'];
			//已有人数
			$item['teamnum']=pdo_count('jy_aligroup_groups_order',array('uniacid'=>$_SESSION['uniacid'],'teamid'=>$item['id'],'status'=>1));
			//到期时间
			$item['endtime']=$group['endtime']*60*60+$item['createtime'];
						  
			$item['nickname']=$heads['nickname']?$heads['nickname']:$member['nickname'];
			$item['grouptitle']=$group['title'];
			$item['corpstitle']=$corps['title'];
			$item['goodstitle']=$goods['title'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'id','title'=>'团ID','type'=>'string'),
			array('name'=>'nickname','title'=>'团长昵称','type'=>'string'),
			array('name'=>'teamnum','title'=>'已参团人数','type'=>'string'),
			array('name'=>'groupnum','title'=>'成团人数','type'=>'string'),
			array('name'=>'grouptitle','title'=>'活动名称','type'=>'string'),
			array('name'=>'corpstitle','title'=>'战队名','type'=>'string'),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'createtime','title'=>'开团时间','type'=>'string'),
			array('name'=>'endtime','title'=>'到期时间','type'=>'time'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		)),
		'search'=>array(
			array('name'=>'id','title'=>'团ID','type'=>'string','width'=>15),
			array('name'=>'nickname','title'=>'团长昵称','type'=>'string','width'=>15),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
